package com.boxin.ims.modules.wechat.entity;

import java.util.Map;

/**
 * @author xiaoqian
 *
 *<xml>
	<ToUserName><![CDATA[toUser]]></ToUserName>
	<FromUserName><![CDATA[fromUser]]></FromUserName>
	<CreateTime>1357290913</CreateTime>
	<MsgType><![CDATA[voice]]></MsgType>
	<MediaId><![CDATA[media_id]]></MediaId>
	<Format><![CDATA[Format]]></Format>
	<Recognition><![CDATA[腾讯微信团队]]></Recognition>//当开启语音识别时此字段为解析后的语音
	<MsgId>1234567890123456</MsgId>
</xml>
*	2014下午5:31:03
 */
public class VoiceMessage extends Message{
	public final static String MSG_TYPE = "voice";
	
	private String MediaId;
	private String Format;
	private String Recognition;
	
	public VoiceMessage(Map<String,String> textMap) {
			this.setToUserName(textMap.get("xml.FromUserName"));
			this.setFromUserName(textMap.get("xml.ToUserName"));
			this.setCreateTime(textMap.get("xml.CreateTime"));
			this.setMsgType("voice");
			this.setMsgId(textMap.get("xml.MediaId"));
			this.setFormat(textMap.get("xml.Format"));
			this.setRecognition(textMap.get("xml.Recognition"));
			this.setMsgId(textMap.get("xml.MsgId"));
	}
	@Override
	public String getMsgType() {
		return MSG_TYPE;
	}
	
	
	/**
	 * <xml>
		<ToUserName><![CDATA[toUser]]></ToUserName>
		<FromUserName><![CDATA[fromUser]]></FromUserName>
		<CreateTime>12345678</CreateTime>
		<MsgType><![CDATA[voice]]></MsgType>
		<Voice>
		<MediaId><![CDATA[media_id]]></MediaId>
		</Voice>
		</xml>
	 */
	@Override
	public String replyMessage() {
		StringBuffer sb  = new StringBuffer();
		sb.append("<xml>");
		sb.append("\t").append("<ToUserName><![CDATA["+this.getToUserName()+"]]></ToUserName>").append("\n");
		sb.append("\t").append("<FromUserName><![CDATA["+this.getFromUserName()+"]]></FromUserName>").append("\n");
		sb.append("\t").append("<CreateTime>"+System.currentTimeMillis()+"</CreateTime>").append("\n");
		sb.append("\t").append("<MsgType><![CDATA[voice]]></MsgType>").append("\n");
		
		sb.append("\t").append("<Voice>").append("\n");
		sb.append("\t").append("<MediaId><![CDATA["+this.getMediaId()+"]]></MediaId>").append("\n");
		sb.append("\t").append("</Voice>").append("\n");
		sb.append("</xml>");
		return sb.toString();
	}
	public String getMediaId() {
		return MediaId;
	}
	public void setMediaId(String mediaId) {
		MediaId = mediaId;
	}
	public String getFormat() {
		return Format;
	}
	public void setFormat(String format) {
		Format = format;
	}
	public String getRecognition() {
		return Recognition;
	}
	public void setRecognition(String recognition) {
		Recognition = recognition;
	}
}
